const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const {CleanWebpackPlugin} = require("clean-webpack-plugin");
module.exports = {
  mode: "development",
  entry: {
    app: './src/index.js'
  },
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  resolve: {
    extensions: [".js", ".jsx"],
    alias: {
      "@": path.join(__dirname, "src"),
      css: path.join(__dirname, "src/css"),
      page: path.join(__dirname, "src/component")
    }
  },
  module: {
    rules: [
      {
        test: /\.js?$/,
        exclude: /node_modules/,
        use: [
          {
            loader: "babel-loader"
          }
        ]
      },
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader'
        ]
      },

      {
        test: /\.(png|svg|jpg|gif|jpeg)$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              outputPath: './',  // 指定图片输入的文件夹,这个目录以dist为基准
              publicPath: './',  // 指定获取图片的路径，这个目录以dist为基准
              limit: 500,
              name: '[name]_[hash].[ext]?[hash]'  // 输入的图片名
            }
          }],
      },
      {
        test: /\.(png|svg|jpg|gif)$/,
        use: [
          'file-loader'
        ]
      }
      ,
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/,
        use: [
          'file-loader'
        ]
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      inject: 'body',
      title: 'Output Management',
      filename: "index.html",
      template: 'index.html',
      favicon: 'assets/images/fm.png'

    })
  ],
  devtool: 'inline-source-map',
  devServer: {
    contentBase: './dist',
    compress: true,
    port: 9000,
    hot: true,
    historyApiFallback: true
  },
};
